<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="button" value="中文" @click="changeLang('zh')" >
        <input type="button" value="english"  @click="changeLang('en')" >
        <p>language:{{language}}</p>
        <hr/>
        <h1>{{lang("reg","title")}}</h1>
        <p>
           {{lang("reg","username")}}:<input type="text" v-model="username"/>
        </p>
        <p>
            {{lang("reg","userpass")}}:<input type="password" v-model="userpass"/>
        </p>
        <p>
            {{lang("reg","userpass2")}}:<input type="password" v-model="userpass2" />
        </p>
        <p>
            <input type="button" :value='lang("reg","regButton")' @click="regSave">
        </p>
    </div>
</body>

</html>
<script src="./js/vue.global.js"></script>
<script src="./js/uIi18n.js"></script>
<script>

    // 国际化插件：
    let i18n = {
        install(app,options){
            // app：就是项目的app。
            // 1、定义一个全局变量，来保存当前项目（app）使用的语言类型   
            //  vue2的写法：Vue.prototype.lang = function(){}
            app.config.globalProperties.lang = function(pagename,key){
                return options[pagename][this.$root.language][key];
            }      
        }
    }

    const {createApp} = Vue;
    
    let app = createApp({
        components:{},
        data(){
            return {
                username:"",
                userpass:"",
                userpass2:"",
                language:"zh"
            }
        },
        created(){
            console.log("this.language",this.language);
        },
        methods:{
            changeLang(language){
                this.language = language;
            },
            regSave(){                
                if(this.userpass!=this.userpass2){
                    alert(this.lang("reg","errMsgPass"));
                }
            }
        }  
    });

    app.use(i18n,uIObj);

    app.mount("#app");


</script>